# -*- coding: utf-8 -*-
"""
Created on Mon Jun 21 14:58:59 2021
野生猪肉分析师
@author: 59567
"""
import sys
sys.path.append("../")
import datetime
import os
import pandas as pd
import numpy as np 
from tjdutils.utils import check_path
from MYSQL.y_assemble import y_assemble_update
from MYSQL.daily_update import daily_update


def loading_y(freq="M", data_type="all"):  # 自动获取最新的y_plus_集合.xlsx, 每日重置一次, 放在input文件夹
    today = str(datetime.date.today())
    path = check_path(f"../input/y_plus_集合{today}.xlsx")
    if os.path.exists(path):
        print("laoding%s" % path, "如果需要最新数据需要在input文件夹删除相应文件")
        yyy = pd.read_excel(path, index_col=0)
    else:
        print('loading y集合from mysql......如果重置需要在input文件夹下清除相应的缓存文件')
        yyy = y_assemble_update().select_all_table()
        yyy.to_excel(path)
        print('loading sucess!!, next loading form local input dir')
    return yyy


def loading_daily_y():
    today = str(datetime.date.today())
    path = check_path(f"../input/daily_y{today}.xlsx")
    if os.path.exists(path):
        print("laoding%s" % path, "如果需要最新数据需要在input文件夹删除相应文件")
        yyy = pd.read_excel(path, index_col=0)
    else:
        print('loading daily_y from mysql.....如果重置需要在input文件夹下清除相应的缓存文件')
        yyy = daily_update().select_all()
        yyy.to_excel(path)
        print('loading sucess!!, next loading form local input dir')
    yydata=np.array(yyy, dtype=np.float)
    yydata=pd.DataFrame(yydata,index=yyy.index,columns=yyy.columns)
    return yydata


if __name__ == "__main__":
    #data = loading_y()
    ddt = loading_daily_y()